#define _CRT_SECURE_NO_WARNINGS 1
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    void duplicateZeros(vector<int>& arr)
    {
        signed int cur = 0, dest = -1,n= arr.size() - 1;
        while (dest < n)
        {
            if (arr[cur] == 0) dest++;
            dest++;
            cur++;
        }
        cur--;
        if (dest > n)
        {
            arr[arr.size() - 1] = 0;
            cur--;
            dest -= 2;
        }
        while (cur >= 0)
        {
            if (arr[cur] == 0) arr[dest--] = 0;
            arr[dest--] = arr[cur--];
        }
    }
};
int main()
{
	vector<int> v = { 1,0,2,3,0,0,5,0 };
    Solution().duplicateZeros(v);
	return 0;
}